﻿/**
  ******************************************************************************
  * @file    Libraries/Device/JS32T031/JS32T031_LL_Driver/src/js32t031_ll_lcd.c
  * @author  JUSHENG Application Team
  * @version V1.0.0
  * @date    02-19-2022
  * @brief   This file contains all the LCD LL firmware functions.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 JUSHENG</center></h2>
  *
  *
  *
  ******************************************************************************
  */ 

/* Includes ------------------------------------------------------------------*/
#include "include.h"

/** @addtogroup JS32T031_StdPeriph_Driver JS32T031 Driver
  * @{
  */
  
/** @defgroup lcd_interface_gr LCD Driver
  * @ingroup  JS32T031_StdPeriph_Driver
  * @{
  */

/** @addtogroup LCD_LL_Driver LCD LL Driver
  * @ingroup  lcd_interface_gr
  * @{
  */
  
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/** @defgroup LCD_LL_Inti_Cfg lcd LL Initialization And Configuration
  * @ingroup  LCD_LL_Driver
  * @brief    LCD_LL Initialization And Configuration
  * @{
  */

/**
  * @brief  lcd init
  * @param  p_lcd : pointer to the hardware LCD_TypeDef
  * @param  p_init: pointer to the init stuct TYPE_LL_LCD_INIT
  * @retval None
  */
void ll_lcd_init(LCD_TypeDef *p_lcd, TYPE_LL_LCD_INIT *p_init)
{
    p_lcd->LCD_COM_NUM = LL_LCD_COM_NUM_SET(p_init->duty_type);
    p_lcd->LCD_COM_SEG_ENA = LL_COM_EN(p_init->com_en) | LL_SEG_EN(p_init->seg_en);

    p_lcd->LCD_DIV_CON = p_init->com_clk;

    p_lcd->LCD_CON = (p_lcd->LCD_CON & ~(LL_LCD_CON_VOLTTAGE_SELCETION(ALL_WORD_FF))) | LL_LCD_CON_VOLTTAGE_SELCETION(p_init->voltage_type);

    if(p_init->bias_type == LL_LCD_BIAS_1_2_MODE)
    {
        p_lcd->LCD_CON |= LL_LCD_CON_BIAS_TYPE;
    }
    else
    {
        p_lcd->LCD_CON &= ~(LL_LCD_CON_BIAS_TYPE);
    }

    if(p_init->com_scan == LL_LCD_COM_SCAN_FRAME)
    {
        p_lcd->LCD_CON |= LL_LCD_CON_COM_SCAN_MODE;
    }
    else
    {
        p_lcd->LCD_CON &= ~(LL_LCD_CON_COM_SCAN_MODE);
    }

    p_lcd->LCD_CON |= LL_LCD_CON_LCD_EN | LL_LCD_CON_ANALOG_ENABLE;
}

/**
  * @}
  */

/** @defgroup LCD_LL_Data_Transfers LCD LL Data transfers functions
  * @ingroup  LCD_LL_Driver
  * @brief    LCD_LL Data transfers functions
  * @{
  */

/**
  * @brief  LCD Controller enable
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
void ll_lcd_controller_enable(LCD_TypeDef *p_lcd)
{
    p_lcd->LCD_CON |= LL_LCD_CON_LCD_EN;
}

/**
  * @brief  LCD Controller disable
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
void ll_lcd_controller_disable(LCD_TypeDef *p_lcd)
{
    p_lcd->LCD_CON &= ~(LL_LCD_CON_LCD_EN);
}

/**
  * @brief  LCD analog drive enable enable
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
void ll_lcd_analog_enable(LCD_TypeDef *p_lcd)
{
    p_lcd->LCD_CON |= LL_LCD_CON_ANALOG_ENABLE;
}

/**
  * @brief  LCD analog drive enable disable
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
void ll_lcd_analog_disable(LCD_TypeDef *p_lcd)
{
    p_lcd->LCD_CON &= ~(LL_LCD_CON_ANALOG_ENABLE);
}

/**
  * @brief  LCD scan frame interrupt enable
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
void ll_lcd_scan_frame_interrupt_enable(LCD_TypeDef *p_lcd)
{
    p_lcd->LCD_CON |= LL_LCD_CON_SCAN_FRAME_IE;
}

/**
  * @brief  LCD scan frame interrupt disable
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
void ll_lcd_scan_frame_interrupt_disable(LCD_TypeDef *p_lcd)
{
    p_lcd->LCD_CON &= (~LL_LCD_CON_SCAN_FRAME_IE);
}

/**
  * @brief  LCD dead zone time control set
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @param  val: dead time, 0~255
  * @retval none
  */
void ll_lcd_div_dead_time_set(LCD_TypeDef *p_lcd, u8 val)
{
    p_lcd->LCD_DIV_CON = (p_lcd->LCD_DIV_CON & ~(LL_LCD_DIV_CON_DEAD_ZONE(ALL_WORD_FF))) | LL_LCD_DIV_CON_DEAD_ZONE(val);
}

/**
  * @brief  LCD Each COM take time control
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @param  val: frame rate, 0~255
  * @retval none
  */
void ll_lcd_clk_div_set(LCD_TypeDef *p_lcd, u8 val)
{
   p_lcd->LCD_DIV_CON = (p_lcd->LCD_DIV_CON & ~(LL_LCD_DIV_CON_CLK_DIV(ALL_WORD_FF))) | LL_LCD_DIV_CON_CLK_DIV(val);
}

/**
  * @brief  LCD COM port 18-bit SEG data set
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @param  com_num: COM port num, COM0 - COM3
  * @param  data: high 18-bit SEG data
  * @retval none
  */
void ll_lcd_com_seg_set(LCD_TypeDef *p_lcd, u8 com_num, u32 data)
{
    if(com_num < 4)
    {
        u32 *p_lcd_com = (u32 *)&p_lcd->LCD_COM0_SEG + com_num;
        *p_lcd_com = LL_LCD_COM_SEG_DATA(data);
    }
}

/**
  * @brief  LCD COM port 18-bit SEG data get
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @param  com_num: COM port num, COM0 - COM3
  * @param  data: high 18-bit SEG data
  * @retval none
  */
void ll_lcd_com_seg_get(LCD_TypeDef *p_lcd, u8 com_num, u32 *data)
{
    if(com_num < 4)
    {
        u32 *p_lcd_com = (u32 *)&p_lcd->LCD_COM0_SEG + com_num;
        *data = *p_lcd_com;
    }
}


/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/*************************** (C) COPYRIGHT 2022 JUSHENG ***** END OF FILE *****/
